package com.jic.data.controller;
import com.jic.data.constant.consist.ResponseCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import java.util.List;
import java.util.stream.Collectors;
import com.jic.common.base.vo.RestResult;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import com.jic.data.model.vo.request.CnMapRegionRequest;
import com.jic.data.model.vo.response.CnMapRegionResponse;
import com.jic.data.model.entity.CnMapRegion;
import com.jic.data.service.CnMapRegionService;
/**
 * @Author: 建投数据科技(山东)有限公司 
 * @date: 2020-05-09 17:25:17
 */
 @RestController
 @Slf4j
 @RequestMapping("/cnMapRegion")
 @Api(tags = " [区域表]控制类-PC")
public class CnMapRegionController {

	@Autowired
	private CnMapRegionService cnMapRegionService;
	
/**
 * 新增记录
 * @param request 新增[区域表]请求参数
 * @return CnMapRegionResponse 新增[区域表]响应参数
 * author 建投数据科技(山东)有限公司
 * @date 2020-3-11 20:54:04
 */
@ApiOperation(value = "新增[区域表]记录")
@PostMapping("/save")
@ResponseBody
public RestResult<Long> save(@RequestBody CnMapRegionRequest request) throws Throwable {
 		CnMapRegion cnMapRegion = new CnMapRegion();
		BeanUtils.copyProperties(request, cnMapRegion);
	long flag = cnMapRegionService.save(cnMapRegion);
 return RestResult.success(flag);
}
/**
 * 新增或修改记录
 * @param request 新增或修改[区域表]请求参数
 * @return CnMapRegionResponse 新增或修改[区域表]响应参数
 * author 建投数据科技(山东)有限公司
 * @date 2020-3-11 20:54:04
 */
@ApiOperation(value = "保存或更新[区域表]")
@PostMapping("/saveOrUpdate")
 @ResponseBody
public RestResult<Long> saveOrUpdate(@Validated @RequestBody CnMapRegionRequest request) throws Throwable {
 		CnMapRegion cnMapRegion = new CnMapRegion();
		BeanUtils.copyProperties(request, cnMapRegion);
	long flag =   cnMapRegionService.saveOrUpdate(cnMapRegion);
 return RestResult.success(flag);
}
/**
 * 删除记录
 * @param request 删除[区域表]请求参数
 * @return CnMapRegionResponse 删除[区域表]响应参数
 * author 建投数据科技(山东)有限公司
 * @date 2020-3-11 20:54:04
 */
@ApiOperation(value = "删除[区域表]记录")
@PostMapping("/delete")
@ResponseBody
public RestResult<Long> delete(@RequestBody CnMapRegionRequest request) throws Throwable {
 		CnMapRegion cnMapRegion = new CnMapRegion();
		BeanUtils.copyProperties(request, cnMapRegion);
	long flag = cnMapRegionService.deleteByPrimaryKeyLogically(cnMapRegion);
 return RestResult.success(flag);
}
/**
 * 修改记录
 * @param request 修改[区域表]请求参数
 * @return CnMapRegionResponse 修改[区域表]响应参数
 * author 建投数据科技(山东)有限公司
 * @date 2020-3-11 20:54:04
 */
@ApiOperation(value = "修改[区域表]记录")
@PostMapping("/update")
@ResponseBody
public RestResult<Long> update(@RequestBody CnMapRegionRequest request) throws Throwable {
 		CnMapRegion cnMapRegion = new CnMapRegion();
		BeanUtils.copyProperties(request, cnMapRegion);
	long flag = cnMapRegionService.updateByPrimaryKeySelective(cnMapRegion);
 return RestResult.success(flag);
}
/**
 * 单表查询详情信息
 * @param request 查询[区域表]详情请求参数
 * @return CnMapRegionResponse 查询[区域表]详情响应参数
 * author 建投数据科技(山东)有限公司 
 * @date 2020-3-11 20:54:04
 */
 @PostMapping("/getByPrimaryKey")
 @ApiOperation(value = "查询[区域表]详情")
 @ResponseBody
public RestResult<CnMapRegionResponse> getByPrimaryKey(@Validated  @RequestBody CnMapRegionRequest request) {
	log.info("查询详情请求参数入参，{}", JSONObject.toJSONString(request));
	if (request!=null) {
	 
		CnMapRegion cnMapRegion = new CnMapRegion();
		BeanUtils.copyProperties(request, cnMapRegion);
		CnMapRegion result = cnMapRegionService.getByPrimaryKey(cnMapRegion);
		log.info("查询详情请求参数出参，{}", JSONObject.toJSONString(result));
		if (result == null) {
			return RestResult.error(ResponseCode.EXCEPTION, "记录不存在");
		}
		CnMapRegionResponse bo = new CnMapRegionResponse();
		BeanUtils.copyProperties(result, bo);
		return RestResult.success(bo);
	}
	log.info("查询详情请求结束");
	return RestResult.success(new CnMapRegionResponse());
}
 /**
	 * 分页查询
	*
	* @param request 分页查询请求参数
	* @return 分页列表
	  * @throws Throwable 业务异常和系统异常
	 */
//@PostMapping("/listPage")
//@ApiOperation(value = " 分页查询列表 ")
//@ResponseBody
//public RestResult<PageInfo<CnMapRegion>> listPage (@RequestBody CnMapRegionRequest request) throws Throwable {
// CnMapRegion param = new CnMapRegion();
// BeanUtils.copyProperties(request, param);
//return RestResult.success(cnMapRegionService.listPageBySelective(param, request.getPageSize(), request.getPageNum()));
//}

/**
	 * CN_MAP_REGION 查询列表（不分页）
	 * @param  request 前端请求参数
 */
 @PostMapping("/listAll")
 @ApiOperation(value = "不分页查询 [区域表] ")
 @ResponseBody
 public RestResult<List<CnMapRegionResponse>>  listCnMapRegionAllRecord(@RequestBody CnMapRegionRequest request) throws Throwable {
 		CnMapRegion cnMapRegion = new CnMapRegion();
		BeanUtils.copyProperties(request, cnMapRegion);
		List<CnMapRegion> list = cnMapRegionService.listAllRecord(cnMapRegion);
			List<CnMapRegionResponse> responseList = list.stream().map(temp -> {
			CnMapRegionResponse bo = new CnMapRegionResponse();
			BeanUtils.copyProperties(temp, bo);
			return bo;
			}).filter(item -> item != null).collect(Collectors.toList());
		return RestResult.success(responseList);
}

}

